<script>
	import {mapMutations,mapState,mapActions} from 'vuex';
	import config from "@/api/config";
	import common from "@/common/common";
	import {getConfig,getUserInfo,getVersion} from "@/api/api.js"; 
	export default {
		 globalData:{
			 configInfo:"",//配置信息
			 userInfo:"",//用户信息
		 },
		computed: {
			...mapState(['hasLogin','openFlag'])
		},
		onLaunch: function() {
			console.log('App Launch')
			let that=this;
			//#ifdef H5 
			// //在页面加载时读取sessionStorage里的状态信息
			if (sessionStorage.getItem("store") ) {
				that.$store.replaceState(Object.assign({}, that.$store.state,JSON.parse(sessionStorage.getItem("store"))))
			}
			//在页面刷新时将vuex里的信息保存到sessionStorage里
			window.addEventListener("beforeunload",()=>{
				sessionStorage.setItem("store",JSON.stringify(that.$store.state))
			})
			// #endif
		
			if(this.hasLogin){
				this.getUserInfo()
				
			}
			this.getConfig()
			/*获取设备信息 （高度）*/
			//#ifdef MP
			let menuButtonObject=uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonObject)
			uni.getSystemInfo({
				success:function (res){
					console.log(res)
					let statusBarHeight= res.statusBarHeight;//设备顶部标签信息
					let navTop= menuButtonObject.top;//胶囊按钮与顶部的距离
					let navHeight = statusBarHeight + menuButtonObject.height + (navTop - statusBarHeight) *2//导航的高度
					// that.globalData.navHeight=navHeight;
					// that.globalData.navTop=navTop;
					// that.globalData.windowHeight=res.windowHeight;
					let systemData={
						navHeight:navHeight,
						navTop:navTop,
					}
					that.setnavHeight(systemData)
				}
			}) 
			// #endif
			if(process.uniEnv.ISOPENSOURCE){
				this.getVersion()
			}
			
		},
		onShow: function() {
			
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			...mapMutations(['login','setnavHeight','updateOpenFlag']),
			...mapActions(['getConfig']),
			/*配置信息*/ 
			// getConfig(){
			// 	getConfig().then(res=>{
			// 		if(res){
			// 			// console.log(res)
			// 			this.globalData.configInfo=res;
			// 		}
					
			// 	}) 
			// },
			/*用户信息*/
			getUserInfo(){
				getUserInfo().then(res=>{
					if(!res.msg=="-100"){
						// console.log(res)
						if(res.head_pic.indexOf("public")==1){ //判断头像 是否有 域名
							var hostUrl=config.host;//路径前缀
							res.head_pic= hostUrl+res.head_pic;//路径前缀
						}
						this.globalData.userInfo=res
					}
				})
			},
			getVersion(){ //开源版本更新提示
				console.log(process.uniEnv);
				uni.request({
					url:'http://www.vueshop.com.cn/index.php?version=java', 
					header: {
						'content-type': 'application/json' ,// 默认值
					},
					success: (res) => {
						console.log(res)
						if(res.data.status==1){
							if(res.data.version!=process.uniEnv.BASE_VERSION){
								// common.toast("none",'请去官网下载最新版本',3000)
								uni.showModal({
									title: '提示',
									content: res.data.msg,
									success: function (res) {
										if (res.confirm) {
											window.location.href="http://www.vueshop.com.cn/"
										} else if (res.cancel) {
											console.log('用户点击取消');
										}
									}
								});
							}else{
								this.updateOpenFlag(false);
							}
						}
					}
				});

			}
			
		}
	}
</script>

<style>
	   @import './common/css/uni.css';
	/*每个页面公共css */
	/* 空白页 */
	.red{
		color: #ff3b3b;
	}
	.flex {
	  display: flex;
	}
	.flex_auto {
	  flex: 1;
	}
	.container {
	    font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
	    display: flex;
	    flex-direction: column;
	    justify-content: space-between;
	    box-sizing: border-box;
	    padding-bottom:134rpx;
	
	}
	page {
	    background-color: #f5f5f5;
	}
	button{
	    border-radius: 0;
	    padding-left: 0;
	    padding-right: 0;
	    background-color:transparent;
	    font-size: 28rpx;
	}
	.wh100{
	    width: 100%;
	    height: 100%;
	}
	/* 
	    单行文本超出隐藏,
	    要使用的div必须要有宽和高
	 */
	.ellipsis-1{   
	    overflow: hidden;
	    white-space: nowrap;
	    text-overflow: ellipsis;
	}
	/* 
	    两行文本超出隐藏,
	    要使用的div必须要有宽和高
	 */
	.ellipsis-2{
	    overflow:hidden; 
	    text-overflow:ellipsis;
	    display:-webkit-box; 
	    -webkit-box-orient:vertical;
	    -webkit-line-clamp:2;
	}
	.pd-bg-fff{
	    padding: 0 30rpx 0rpx;
	    background-color: #fff;
	    font-size:32rpx
	}
	.co-red{
	    color: #ff3b3b;
	}
	.hide{
	    display: none;
	}
	.t-c{
	    text-align: center;
	}
	/* 掩盖层 */
	.cover-layer{
	    position: fixed;
	    left: 0;
	    top: 0;
	    right: 0;
	    bottom: 0;
	    z-index: 11;
	    background: rgba(0,0,0,0.4);
	    width: 100%;
	    height: 100%;
	}
	/* 弹框的关闭按钮 */
	.modal-close{
	    position: absolute;
	    right: 25rpx;
	    top: 25rpx;
	}
	/* 空白页 */
	.no-data{
	    width: 100%;
	    text-align: center;
	}
	.no-data .no-data-title{
	    color: #9b9b9b;
	    margin-bottom: 30rpx;
	    font-size: 35rpx;
	}
	.no-data .cart-image {
	    width: 140px;
	    height: 140px;
	    margin-top: 100rpx;
	}
	.no-data .lookat{
	    padding: 16rpx 40rpx;
	    background-color: white;
	    display: inline;
	    margin: 0 auto;
	    border-radius: 10rpx;
	}
	.next_icon{
	  width: 32rpx;
	  height: 32rpx;
	}
	.choosebox{
	  width: 40rpx;
	  height: 40rpx;
	  display: inline-block;
	}
	.choosebox image{
	  width: 100%;
	  height: 100%;
	  display: block;
	}
	.red-on {
	  color: #ff3b3b;
	  font-weight: bold;
	}
	
	.little-btn-1 {
	  width: 150rpx;
	  height: 48rpx;
	  line-height: 48rpx;
	  text-align: center;
	  margin-left: 20rpx;
	  border-radius: 5rpx;
	  background: #FF3B3B;
	  color: #fff;
	  font-size: 24rpx;
	  border: 1rpx solid #FF3B3B;
	  box-sizing: border-box;
	  display: inline-block;
	}
	
	.little-btn-2 {
	  width: 150rpx;
	  height: 48rpx;
	  line-height: 48rpx;
	  text-align: center;
	  margin-left: 20rpx;
	  border-radius: 5rpx;
	  background: #fff;
	  color: #999999;
	  font-size: 24rpx;
	  border: 1rpx solid #E6E6E6;
	  box-sizing: border-box;
	  display: inline-block;
	}
</style>
